package movee.io.cmd.service;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 *
 * @author movee
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SendTemplateQuery {

    private String userName;
    private List<Template> templates;
    private List<Device> devices;


    public static SendTemplateQuery build(String mgmtIp,
                                          String templateName,
                                          Map<String, Object> templateParams) {

        Template template = new Template();
        template.setId(null);
        template.setProtocol("");
        template.setCommandName(templateName);
        template.setCmdInputParams(templateParams == null ? new HashMap<>() : templateParams);

        Device device = new Device();
        device.setIp(mgmtIp);
        device.setNwId("");
        device.setWarehouse("");

        return new SendTemplateQuery("netconf", Lists.newArrayList(template), Lists.newArrayList(device));
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Template {
        /**
         * 模板ids
         */
        private String id;

        /**
         * 模板名
         */
        private String commandName;

        /**
         * 渲染参数
         */
        private Map<String, Object> cmdInputParams;

        /**
         * 下发的协议，telnet、netconf等
         */
        private String protocol;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Device {
        private String nwId;
        private String ip;
        private String warehouse;
    }
}
